# -*- coding: utf-8 -*-
# @Time : 2021/9/10 16:31
# @Author : 伟哥
# @Email : xw@gmail.com
# @File : shangji_page.py
# @Project : crm
'''商机页面的定位器以及操作方法'''

from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select


from page.base_page import BasePage
from utils.util import HOST
class ShangJI(BasePage):
    '''商机页面的定位器以及操作方法'''
    url="{}/index.php?m=business".format(HOST)
    tianjia_locator=(By.CSS_SELECTOR,'.btn.btn-primary')
    shangjixuanze_locator = (By.TAG_NAME, 'input')
    shanchu_locator = (By.CSS_SELECTOR, "#delete")
    wofzd_locator = (By.LINK_TEXT, "我负责的")
    tiaojian_locator = (By.CSS_SELECTOR, "#field")
    guanxi_locator = (By.CSS_SELECTOR, "#condition")
    shoushuokuang_locator = (By.CSS_SELECTOR, "#search")
    shoushuo_locator = (By.CSS_SELECTOR, "#dosearch")
    xuanze_locator=(By.XPATH,"//*[@id='form1']/table/tbody/tr[1]/td[1]/input")
    chakan_locator=(By.LINK_TEXT,'查看')
    bianji_locator=(By.LINK_TEXT,'编辑')
    tishi_locator=(By.XPATH,"/html/body/div[5]/div[2]")
    table_locater=(By.TAG_NAME,"tbody")
    tr_locator=(By.TAG_NAME,"tr")
    td_locater=(By.TAG_NAME,"td")
    yeshu_locator=(By.XPATH,'//*[@id="td_colspan"]/div[1]/div[1]')
    xiayiye_locator=(By.XPATH,'//*[@id="td_colspan"]/div[1]/div[2]/div/ul/li[4]/span')
    def tianjia(self):
        '''点击添加产品'''
        self.driver.find_element(*self.tianjia_locator).click()

    def chakan(self):
        '''点击查看商品详细信息'''
        self.driver.find_element(*self.chakan_locator).click()

    def bianji(self):
        '''进入编辑产品页面'''
        self.driver.find_element(*self.bianji_locator).click()


    def xuanze_shangji(self,element):
        '''根据输入的对象点击选择商机'''
        element.find_element(*self.shangjixuanze_locator).click()

    def shanchu(self):
        '''点击删除按钮'''
        self.driver.find_element(*self.shanchu_locator).click()
        self.driver.switch_to.alert.accept()

    def wofzd(self):
        """点击我负责的"""
        self.driver.find_element(*self.wofzd_locator).click()

    def tiaojian(self,tiaojian):
        '''根据输入的值选择搜索条件'''
        tiaojian_element=self.driver.find_element(*self.tiaojian_locator)
        tiaojian_select = Select(tiaojian_element)
        tiaojian_select.select_by_visible_text(tiaojian)

    def guanxi(self,guanxi):
        '''根据输入的搜索条件的前后关系，选择'''
        guanxi_element = self.driver.find_element(*self.guanxi_locator)
        guanxi_select = Select(guanxi_element)
        guanxi_select.select_by_visible_text(guanxi)

    def shuoshoukuang(self,shurukuang):
        '''搜索框输入搜索条件'''
        self.driver.find_element(*self.shoushuokuang_locator).send_keys(shurukuang)

    def shuoshou(self):
        '''点击搜索按钮'''
        self.driver.find_element(*self.shoushuo_locator).click()

    def yihangshuju(self):
        '''点击商机表格第一行的方框'''
        self.driver.find_element(*self.xuanze_locator).click()


    def tishi(self):
        '''提示语'''
        return self.driver.find_element(*self.tishi_locator).text

    def yeshu(self,num=9):
        '''获取商机数据页数'''
        txt=self.driver.find_element(*self.yeshu_locator).text
        return txt[num]

    def xiayiye(self):
        '''点击下一页'''
        self.driver.find_element(*self.xiayiye_locator).click()

